package com.ciei.dpagm.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;

import java.util.ArrayList;
import java.util.List;

/**
 * 逻辑运算符枚举
 * @author pp
 * @date 2023/03/11
 */
public enum RelationalOperatorEnum {

    /**
     * 等于
     */
    EQUAL("=="),
    /**
     * 不等于
     */
    NOT_EQUAL("!="),
    /**
     * 大于
     */
    GREATER_THAN(">"),
    /**
     * 大于等于
     */
    GREATER_THAN_OR_EQUAL(">="),
    /**
     * 小于
     */
    LESS_THAN("<"),
    /**
     * 小于等于
     */
    LESS_THAN_OR_EQUAL("<=");

    @EnumValue
    private String operator;

    RelationalOperatorEnum(String operator) {
        this.operator = operator;
    }

    public String getOperator() {
        return operator;
    }

    public static List<String> getOperatorList(){
        RelationalOperatorEnum[] relationalOperatorEnums = RelationalOperatorEnum.values();
        List<String> typeList = new ArrayList<>();
        for(RelationalOperatorEnum relationalOperatorEnum : relationalOperatorEnums){
            typeList.add(relationalOperatorEnum.getOperator());
        }
        return typeList;
    }

    public static RelationalOperatorEnum getEnumByOperator(String operator) {
        for (RelationalOperatorEnum relationalOperatorEnum : values()) {
            if (relationalOperatorEnum.getOperator().equals(operator)) {
                return relationalOperatorEnum;
            }
        }
        return null;
    }
}
